package cn.zc.curriculum.service.controller.admin;

import cn.tools.core.VO.PageVO;
import cn.tools.core.base.R;
import cn.zc.curriculum.entity.Dto.QuestionBankDto;
import cn.zc.curriculum.entity.VO.QuestionBankVO;
import cn.zc.curriculum.service.service.QuestionBankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "后台练习题接口")
@RestController
@RequestMapping("/curriculum")
public class AdminQuestionBankController {
    @Resource
    private QuestionBankService questionBankService;


    /**
     * 创建练习题接口
     * @param questionBankDto
     * @return
     */
    @ApiOperation(value = "创建练习题接口")
    @PostMapping("/admin/create/QuestionBank")
    private R createQuestionBank(@RequestBody QuestionBankDto questionBankDto){
        questionBankService.createQuestionBank(questionBankDto);
        return R.success();
    }

    /**
     * 修改练习题接口
     * @param questionBankDto
     * @return
     */
    @ApiOperation(value = "修改练习题接口")
    @PutMapping("/admin/update/QuestionBank")
    private R updateQuestionBank(@RequestBody QuestionBankDto questionBankDto){
        questionBankService.updateQuestionBank(questionBankDto);
        return R.success();
    }

    /**
     * 删除练习题接口
     * @param id
     * @return
     */
    @ApiOperation(value = "删除练习题接口")
    @PostMapping("/admin/delete/QuestionBank")
    private R deleteQuestionBank(String id){
        questionBankService.deleteQuestionBank(id);
        return R.success();
    }


    /**
     * 查询练习题接口
     * @param pageVO
     * @param questionBankVO
     * @return
     */
    @ApiOperation(value = "查询练习题接口")
    @GetMapping("/admin/find/QuestionBank")
    private R<Object> findQuestionBank(PageVO pageVO, QuestionBankVO questionBankVO){
        List<QuestionBankDto> questionBankDto = questionBankService.findQuestionBank(pageVO,questionBankVO);
        return R.success(questionBankDto);
    }


    /**
     * 根据目录id查询对应的题库
     * @param pageVO
     * @param menuId
     * @return
     */
    @ApiOperation(value = "根据目录id查询目录下练习题")
    @GetMapping("/admin/find/QuestionBankByMenu")
    private R<Object> findQuestionBankByMenu(PageVO pageVO,String menuId){
        List<QuestionBankDto> byMenu = questionBankService.findQuestionBankByMenu(pageVO, menuId);
        return R.success(byMenu);
    }

}